//中文
var data_zh = ['你知道吗', '六月', '一日', '星期一', '是', '儿童节'];
//英语
var data_en = ['do you know', 'June', 'One day', 'Monday', 'Yes', 'Children\'s day'];

//左侧的语言显示
var btn_if = document.querySelectorAll("#btn_if button");

//右侧的语言显示
var btn_that = document.querySelectorAll("#btn_that button");

//点击切换语言
var btn_swap = document.querySelector("#btn_swap");

//左侧输入内容
var text_if = document.querySelector("#text_if");

//右侧翻译结果
var text_that = document.querySelector("#text_that");

//翻译按钮
var btn_res = document.querySelector("#btn_res");

//默认语言是中文
var lang = 'zh';

//切换语言
function lan(){
    //切换默认语言用的
    if (lang == 'zh'){
        lang ='en';
    }else {
        lang = 'zh';
    }
    for(var i = 0;i < btn_if.length;i++){
        btn_if[i].classList.remove('btn-primary');
        btn_if[i].classList.remove('btn-light');
        btn_that[i].classList.remove('btn-primary');
        btn_that[i].classList.remove('btn-light');
    }
    switch (lang){
        case 'zh':
            btn_if[0].classList.add('btn-primary');
            btn_if[1].classList.add('btn-light');
            btn_that[0].classList.add('btn-primary');
            btn_that[1].classList.add('btn-light');
            break;
        case 'en':
            btn_if[1].classList.add('btn-primary');
            btn_if[0].classList.add('btn-light');
            btn_that[1].classList.add('btn-primary');
            btn_that[0].classList.add('btn-light');
            break;
    }
}
//点击翻译按钮的方法
function res(){
    //数据
    var data;
    //检测数据库里面有没有这个词汇
    var if_text = false;

    //看看中文词库里面有没有这个词语
    //noinspection JSDuplicatedDeclaration
    for(var i in data_zh){
        if(text_if.value == data_zh[i]){
            if_text = true;
            data = data_zh;
            text_that.value = data_en[i];

            if (lang != 'en') {
            } else {
                lan();
            }
        }
    }
    //看看英语词库里面有没有这个词语
    //noinspection JSDuplicatedDeclaration
    for(var i in data_en){
        if (text_if.value != data_en[i]) {
        } else {
            if_text = true;
            data = data_en;
            text_that.value = data_zh[i];

            if ('zh' == lang) {
                lan();
            }
        }
    }
    if(!if_text){
        text_that.value = '';
        alert("无法翻译");
    }
}
